﻿<%@ Page Title="" Language="C#" MasterPageFile="~/resumemanager/resume.master" Inherits="WebManager.BasePage" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<%@ Import Namespace="TalentPools.Model" %>
<%@ Import Namespace="TalentPools.BLL" %>
<script runat="server">

    private int resumeId;

    public int ResumeId
    {
        get { return Convert.ToInt32(ViewState["resumeId"]); }
        set { ViewState["resumeId"] = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        MyUserLogin();
        if (!IsPostBack)
        {
            ResumeId = Convert.ToInt32(Request.QueryString["resumeId"]);

                this.txtbegintime.Attributes.Add("ReadOnly", "true");
                this.txtendtime.Attributes.Add("ReadOnly", "true");
                this.txtBeginTime1.Attributes.Add("ReadOnly", "true");
                this.txtEndTime1.Attributes.Add("ReadOnly", "true");
           
        }
        DataBind(ResumeId);
    }
    private void DataBind(int resumeId)
    {
        List<training> list = new TrainingManager().GetTrains(resumeId);
        dlTrainning.DataSource = list;
        dlTrainning.DataBind();
    }

    protected void imgbtnmynext_Click(object sender, ImageClickEventArgs e)
    {
        if (CreateTraining())
            DataBind(ResumeId);
    }

    protected void lbtnContinueTran_Click(object sender, EventArgs e)
    {
        if (CreateTraining())
        {
            txttittle.Text = "";
            txtbegintime.Text = "";
            txtendtime.Text = "";
            txtresult.Text = "";
            txtdetail.Text = "";
            DataBind(ResumeId);
        }
    }

    private bool CreateTraining()
    {
        training tr = new training();
        tr.tittle = txttittle.Text.Trim();
        tr.beginTime = Convert.ToDateTime(txtbegintime.Text.ToString());
        tr.endTime = Convert.ToDateTime(txtendtime.Text.ToString());
        tr.result = txtresult.Text.ToString();
        tr.details = txtdetail.Text.ToString();
        tr.resumeId = ResumeId;
        return new CreateresumeManager().createTraning(tr);
    }
    private bool SaveTraining(int trainingId)
    {
        training tr = new training();
        tr.tittle = txtTitle1.Text.Trim();
        tr.trainingId = trainingId;
        tr.beginTime = Convert.ToDateTime(txtBeginTime1.Text.Trim());
        tr.endTime = Convert.ToDateTime(txtEndTime1.Text.Trim());
        tr.result = txtResult1.Text.Trim();
        tr.details = txtDetails.Text.Trim();
        tr.resumeId = ResumeId;
        return new alertResumeManager().updateTraning(tr);
    }

    protected void dlTrainning_EditCommand(object source, DataListCommandEventArgs e)
    {
        ViewState["trainingId"] = dlTrainning.DataKeys[e.Item.ItemIndex];
        training train = new TrainingManager().GetTrain(ResumeId, Convert.ToInt32(ViewState["trainingId"]));
        txtTitle1.Text = train.tittle;
        txtResult1.Text = train.result;
        txtEndTime1.Text = train.endTime.ToShortDateString();
        txtBeginTime1.Text = train.beginTime.ToShortDateString();
        txtDetails.Text = train.details;
        ClientScript.RegisterStartupScript(typeof(string), "", "<scr" + "ipt" + ">edit();</sc" + "ript>");

    }

    protected void dlTrainning_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int trainingId =Convert.ToInt32(dlTrainning.DataKeys[e.Item.ItemIndex]);
        if (new TrainingManager().DeleteTraining(trainingId))
        {
            DataBind(ResumeId);
        }
    }

    protected void ibtnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (SaveTraining(Convert.ToInt32(ViewState["trainingId"])))
        {
            DataBind(ResumeId);
        }
    }

    protected void lbtnConAdd_Click(object sender, EventArgs e)
    {
        if (SaveTraining(Convert.ToInt32(ViewState["trainingId"])))
        {
            DataBind(ResumeId);
            ClientScript.RegisterStartupScript(typeof(string), "", "<scr" + "ipt" + ">edit1();</sc" + "ript>");
        }
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script src="../js/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../js/jquery-1.6.2.min.js" type="text/javascript"></script>
    <style type="text/css">
        #add
        {
           display:block;
        }
        #update
        {
            display:none;
        }
    </style>
    <script type="text/javascript">
        function edit() {
            $("#add").css("display", "none");
            $("#update").css("display", "block");
        }
        function edit1() {
            $("#add").css("display", "block");
            $("#update").css("display", "none");
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div id="tranningList">
        <asp:DataList ID="dlTrainning" runat="server" CssClass="tranningList" OnEditCommand="dlTrainning_EditCommand"
            OnDeleteCommand="dlTrainning_DeleteCommand" DataKeyField="trainingId">
            <HeaderTemplate>
                <table class="tableMain" style="width: 100%">
                    <tr>
                        <td class="titleStyle" style="text-align: center; width: 20%;">
                            名称
                        </td>
                        <td class="valStyle" style="text-align: center; width: 35%;">
                            开始时间-结束时间
                        </td>
                        <td class="textStyle" style="text-align: center; width: 30%;">
                            证书
                        </td>
                        <td class="editStyle" style="width: 15%">操作
                        </td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td class="titleStyle" style="text-align: center; width: 20%;">
                        <%#Eval("tittle") %>
                    </td>
                    <td class="valStyle" style="text-align: center; width: 35%;">
                        <%#WebManager.BasePage.SetTimeFormat(Convert.ToDateTime(Eval("beginTime"))) %>—<%#WebManager.BasePage.SetTimeFormat(Convert.ToDateTime(Eval("endTime"))) %></td>
                    <td class="textStyle" style="text-align: center; width: 30%;">
                        <%#Eval("result") %>
                    </td>
                    <td class="editStyle" style="width: 15%">
                        <asp:LinkButton ID="lbtnEdit" runat="server" Text="编辑" CommandName="Edit"></asp:LinkButton> | 
                        <asp:LinkButton ID="lbtnDel" runat="server" Text="删除" CommandName="Delete" OnClientClick="return confirm(&quot;确认要删除吗？&quot;)"></asp:LinkButton>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:DataList>
    </div>
    <div id="add">
        <br />
        <span style="height: 25px; font-family: 微软雅黑 宋体; font-size: 14px; text-align: left;">
            新增培训</span>
        <br />
        <br />
        <table class="tableMain">
            <tr>
                <td class="titleStyle">
                    名称:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txttittle" runat="server" ValidationGroup="three" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator18" runat="server" ControlToValidate="txttittle"
                        ErrorMessage="*必填" ValidationGroup="three" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    开始时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtbegintime" runat="server" BorderStyle="None" Width="195px" Style="margin-bottom: 0px"
                        ValidationGroup="three"></asp:TextBox>
                    <asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtbegintime" runat="server">
                    </asp:CalendarExtender>   
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator19" runat="server" ControlToValidate="txtbegintime"
                        ErrorMessage="*必填" ValidationGroup="three" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    截止时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtendtime" runat="server" ValidationGroup="three" CssClass="Wdate"
                        Width="195px"></asp:TextBox><asp:CalendarExtender ID="CalendarExtender2" TargetControlID="txtendtime" runat="server">
                        </asp:CalendarExtender>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator20" runat="server" ControlToValidate="txtendtime"
                        ErrorMessage="*必填" ValidationGroup="three" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    获得证书:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtresult" runat="server" ValidationGroup="three" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    详细描述:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtdetail" runat="server" ValidationGroup="three" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:ImageButton ID="imgbtnmynext" runat="server" ImageUrl="~/img/create.gif" OnClick="imgbtnmynext_Click" />
                    &nbsp;
                    <asp:LinkButton ID="lbtnContinueTran" runat="server" OnClick="lbtnContinueTran_Click">新增并继续添加培训信息</asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
    <div id="update">
        <span style="width: 90%; height: 25px; font-family: 微软雅黑 宋体; font-size: 14px; color: #000;
            background-color: #fff; text-align: left;">修改培训</span>
        <table class="tableMain">
            <tr>
                <td class="titleStyle">
                    名称:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtTitle1" runat="server" ValidationGroup="three" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtTitle1"
                        ErrorMessage="*必填" ValidationGroup="three" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    开始时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtBeginTime1" runat="server" BorderStyle="None" Width="195px" Style="margin-bottom: 0px"
                        ValidationGroup="three"></asp:TextBox><asp:CalendarExtender ID="CalendarExtender4"
                            runat="server" TargetControlID="txtBeginTime1">
                        </asp:CalendarExtender>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtBeginTime1"
                        ErrorMessage="*必填" ValidationGroup="three" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    截止时间:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtEndTime1" runat="server" ValidationGroup="three" CssClass="Wdate"
                        Width="195px"></asp:TextBox><asp:CalendarExtender ID="CalendarExtender3" TargetControlID="txtEndTime1" runat="server">
                        </asp:CalendarExtender>
                </td>
                <td class="valStyle">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtEndTime1"
                        ErrorMessage="*必填" ValidationGroup="three" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    获得证书:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtResult1" runat="server" ValidationGroup="three" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    详细描述:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtDetails" runat="server" ValidationGroup="three" BorderStyle="None"
                        Width="195px"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:ImageButton ID="ibtnSubmit" runat="server" ImageUrl="~/img/create.gif" OnClick="ibtnSubmit_Click" />&nbsp;
                    <asp:LinkButton ID="lbtnConAdd" runat="server" OnClick="lbtnConAdd_Click">保存修改并继续添加培训信息</asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
